package br.com.reparoja.reparoja.ui;


import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Spinner;

import java.util.Arrays;

import br.com.reparoja.reparoja.R;
import br.com.reparoja.reparoja.adapter.FindServiceProviderAdapter;
import br.com.reparoja.reparoja.adapter.SpeedScrollListener;

/**
 * A simple {@link Fragment} subclass.
 */
public class FindServiceProviderFragment extends Fragment implements View.OnClickListener{

    ProgressBar progressBar;
    ListView listProviders;

    public FindServiceProviderFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_find_service_provider, container, false);

        Spinner equipments = (Spinner) view.findViewById(R.id.spinner_equipments);
        ArrayAdapter<String> equipAdapter = new ArrayAdapter<String>(
                getActivity(),
                android.R.layout.simple_spinner_dropdown_item,
                (String[]) Arrays.asList("Geladeira", "Fogão", "Microondas").toArray());
        equipments.setAdapter(equipAdapter);
        //equipments.setOnItemClickListener(this);

        Spinner brands = (Spinner) view.findViewById(R.id.spinner_brand);
        ArrayAdapter<String> brandAdapter = new ArrayAdapter<String>(
                getActivity(),
                android.R.layout.simple_spinner_dropdown_item,
                (String[]) Arrays.asList("Brastemp", "Consul", "Eletrolux", "Samsung", "Lg").toArray());
        brands.setAdapter(brandAdapter);

        Button search = (Button) view.findViewById(R.id.button_search);
        search.setOnClickListener(this);

        this.listProviders = (ListView) view.findViewById(R.id.service_providers);
        this.progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
                //service_providers



        return view;
    }


    @Override
    public void onClick(View v) {
        this.progressBar.setVisibility(View.GONE);
        this.listProviders.setVisibility(View.VISIBLE);

        SpeedScrollListener listener = new SpeedScrollListener();
        this.listProviders.setOnScrollListener(listener);
        FindServiceProviderAdapter adapter = new FindServiceProviderAdapter(getActivity().getApplicationContext(), listener);
        this.listProviders.setAdapter(adapter);
    }
}
